from django.db import models

from utils.models import BaseModel

class GoodsCategory(BaseModel):
    """商品类别"""
    name = models.CharField(max_length=30, verbose_name='类别名称')
    parent = models.ForeignKey(
        'self',
        related_name='subs',
        null=True,
        blank=True,
        on_delete=models.CASCADE,
        verbose_name='父类别')

    class Meta:
        db_table = 'tb_goods_category'
        verbose_name = '商品类别'
        verbose_name_plural = verbose_name
    def __str__(self):
        return self.name

    # 商品频道组
class GoodsChannelGroup(BaseModel):
        """商品频道组"""
        name = models.CharField(max_length=20, verbose_name='频道组名')

        class Meta:
            db_table = 'tb_channel_group'
            verbose_name = '商品频道组'
            verbose_name_plural = verbose_name

    # 商品频道
class GoodsChannel(BaseModel):
        """商品频道"""
        group = models.ForeignKey(GoodsChannelGroup, related_name='channels', on_delete=models.CASCADE,
                                  verbose_name='频道组名')
        category = models.ForeignKey(GoodsCategory, related_name='channels', on_delete=models.CASCADE,
                                     verbose_name='商品分类')
        sequence = models.IntegerField(verbose_name='组内顺序')
        index_category = models.BooleanField(default=False, verbose_name='是否在主页展示')

        class Meta:
            db_table = 'tb_goods_channel'
            verbose_name = '商品频道'
            verbose_name_plural = verbose_name